import {Component, TemplateRef, ViewChild} from '@angular/core';
import {TableDirective} from "./table.directive";

@Component({
  selector: 'gn-table-template',
  template: `
    <ng-template #emptyMessage>
      <tr><td align="center">没有记录</td></tr>
    </ng-template>
    <ng-template #paginatorLeft>
      <p-checkbox label="全选" binary="true" *ngIf="table.showSelectAll" [(ngModel)]="table.selectAll"
                  (onChange)="table.selectAllChange()"></p-checkbox>
      <button type="button" *ngIf="table.showRefreshButton" pButton (click)="table.reloadData()" class="ui-button-secondary" icon="pi pi-refresh"></button>
      <button type="button" *ngIf="table.showSearchButton" pButton (click)="table.showSearch = !table.showSearch"
              class="ui-button-secondary" icon="pi pi-search"></button>
    </ng-template>
    <ng-template #paginatorRight>
      <span>共 {{table.table.totalRecords}} 条记录</span>
    </ng-template>
  `
})
export class TableTemplateComponent {

  @ViewChild('emptyMessage') public emptyMessage: TemplateRef<any>;

  @ViewChild('paginatorLeft') public paginatorLeft: TemplateRef<any>;

  @ViewChild('paginatorRight') public paginatorRight: TemplateRef<any>;

  table: TableDirective;

  setTable(table: TableDirective) {
    this.table = table;
  }

}
